package com.pubinfo.passbook.common.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.zip.ZipEntry;

/**
 * <p>
 *
 * </p>
 *
 * @author xuhong
 * @since 2021-11-23
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class TFileInfo implements Serializable {
  
  private static final long serialVersionUID = 1L;
  
  @TableId(type = IdType.ASSIGN_ID, value = "id")
  private String id;
  /**
   * 文件名
   */
  private String name;
  
  /**
   * 文件类型
   */
  private String contentType;
  
  /**
   * 大小
   */
  private Long size;
  
  /**
   * 物理路径
   */
  private String path;
  
  /**
   * 上传人
   */
  private String createBy;
  
  /**
   * 创建时间
   */
  @TableField(fill = FieldFill.INSERT)
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  private Date createTime;
  
  /**
   * 修改人
   */
  private String updateBy;
  
  /**
   * 修改时间
   */
  @TableField(fill = FieldFill.UPDATE)
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  private Date updateTime;
  
  /**
   * 类型 1 票据  2 发票
   */
  private Integer type;
  
  /**
   * 是否删除  0是 1否
   */
  private Integer isDelete;
  
  /**
   * 发票id
   */
  private String invoiceId;
  
  /**
   * 票据id
   */
  private String passbookId;
  
  /**
   * 人工上传id
   */
  private String artificialId;

  /**
   * 银行回单id
   */
  private String bankElectronicReceiptId;


  /**
   * 银行对账单id
   */
  private String bankReconciliationStatementId;


  /**
   * 版式文件解析的发票信息id
   */
  private String newInvoiceId;


  /**
   * 版本号
   */
  private String edition;
  
  public TFileInfo(ZipEntry entry, String path)
  {
    this.name=entry.getName();
    this.contentType="application/ofd";
    this.size=entry.getSize();
    this.path=path;
    this.type=2;
    this.isDelete=1;
    this.invoiceId=entry.getName().split("\\.")[0];
  }

  public TFileInfo(ZipEntry entry, String path,String type,String id)
  {
    this.name=entry.getName();
    this.contentType="application/ofd";
    this.size=entry.getSize();
    this.path=path;
    this.type=2;
    this.isDelete=1;
    if(type.equals("0"))
    {
      bankElectronicReceiptId=id;
    }
    else
    {
      bankReconciliationStatementId=id;
    }
  }


}
